package com.fau.hm.action.index;

import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.fau.hm.action.PublicAction;
import com.fau.hm.entity.MedicalAdmin;
import com.fau.hm.entity.MedicalLeaveNotBy;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @desc 休假管理
 * @author dangjh
 * @datetime 2014年10月26日,上午11:30:10
 */
@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace("/")
public class VacationNotByAction extends PublicAction implements ModelDriven<MedicalLeaveNotBy> {

	private static final long serialVersionUID = 1713700405822813176L;

	private MedicalLeaveNotBy notby = new MedicalLeaveNotBy();
	
	/**
	 * @desc 休假审核未通过信息列表-个人
	 * @return
	 * @author dangjh
	 * @datetime 2014年10月25日,下午3:44:28
	 */
	@Action(value = "init_leave_notby_list", results = {@Result(location = "init_leave_notby_list.jsp")})
	public String initLeaveNotByList(){
		return SUCCESS;
	}
	
	/**
	 * @desc 休假审核未通过数据-个人
	 * @return
	 * @author dangjh
	 * @datetime 2014年10月25日,下午3:48:09
	 */
	@Action(value = "leave_notby_view")
	public String leaveApproveView(){
		HttpServletResponse response = ServletActionContext.getResponse();
		this.map = ActionContext.getContext().getParameters();
		MedicalAdmin admin = (MedicalAdmin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		this.pageBean = this.baseAllService.getLeaveService().findApproveNotByLeave(map, notby, admin);
		this.map.clear();
		map.put("total", this.pageBean.getTotalRow());
		map.put("data", this.pageBean.getResult());
		formatJSON(response, this.map);
		return null;
	}
	
	/**
	 * @desc 查看休假记录
	 * @return
	 * @author dangjh
	 * @datetime 2014年10月26日,下午1:01:02
	 */
	@Action(value = "init_leave_notbylog_list", results = {@Result(location = "init_leave_notbylog_list.jsp")})
	public String leaveLogList(){
		return SUCCESS;
	}
	
	/**
	 * @desc 休假记录数据
	 * @return
	 * @author dangjh
	 * @datetime 2014年10月26日,下午1:03:32
	 */
	@Action(value = "leave_notbylog_view")
	public String leaveLogView(){
		this.map = ActionContext.getContext().getParameters();
		MedicalAdmin admin = (MedicalAdmin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		this.pageBean = this.baseAllService.getLeaveService().findLeaveLogNotByAll(map, notby, admin);
		this.map.clear();
		map.put("total", this.pageBean.getTotalRow());
		map.put("data", this.pageBean.getResult());
		HttpServletResponse response = ServletActionContext.getResponse();
		formatJSON(response, this.map);
		return null;
	}
	
	/**
	 * @desc 审核未通过
	 * @return
	 * @author dangjh
	 * @datetime 2014年10月26日,下午12:58:38
	 */
	@Action(value = "leave_not_pass")
	public String leaveNotPass(){
		HttpServletResponse response = ServletActionContext.getResponse();
		map = new HashMap<String, Object>();
		if(StringUtils.isNotBlank(notby.getInfoId())){
			this.baseAllService.getLeaveService().saveNotByApproveLeave(notby);
			map.put("success", true);
		}else {
			map.put("success", false);
		}
		formatJSON(response, map);
		return null;
	}
	
	/**
	 * @desc 编辑休假信息页
	 * @return
	 * @author dangjh
	 * @datetime 2014年10月13日,下午4:14:12
	 */
	@Action(value = "leave_info_edit", results = {@Result(name = SUCCESS, location = "leave_info_edit.jsp")})
	public String leaveInfoEdit(){
		return SUCCESS;
	}
	
	/**
	 * @desc 编辑未通过休假信息，重新提交请假单
	 * @return
	 * @author dangjh
	 * @datetime 2014年10月13日,下午1:53:30
	 */
	@Action(value = "leave_infoedit_save")
	public String leaveInfoEdidSave(){
		HttpServletResponse response = ServletActionContext.getResponse();
		map = new HashMap<String, Object>();
		if(StringUtils.isNotBlank(notby.getId())){
			this.baseAllService.getLeaveService().saveEditLeaveInfo(notby);
			map.put("success", "true");
		}else{
			map.put("success", "false");
		}
		formatJSON(response, map);
		return null;
	}
	
	@Override
	public MedicalLeaveNotBy getModel() {
		return notby;
	}

}
